import { HashRouter, Redirect, Route, Switch } from "react-router-dom/cjs/react-router-dom";
import Login from "../views/Login";
import NewsSandBox from "../views/sandbox/NewsSandBox";

function loggedIn() {
    return window.localStorage.getItem('token');
}

function IndexRouter() {
    return (
        <HashRouter>
            <Switch>
                <Route path="/login" component={Login} />
                <Route path="/" render={() => loggedIn() ? <NewsSandBox /> : <Redirect to="/login" />} />
            </Switch>
        </HashRouter>
    );
}

export default IndexRouter;